﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ThuatToanKNN
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtDuongDan.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa chọn đường dẫn đến file txt Input", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtout.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa chọn đường dẫn đến file txt Output", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string path = txtDuongDan.Text.Trim();
            string pathResult = txtout.Text.Trim();
            ThuatToanKNN.Cores.KNN_Algorithms m_handle = new ThuatToanKNN.Cores.XuLy();
            string str = m_handle.KNN(path);
            m_handle.WriteFile(pathResult, str);
            lbResult.Text = str;
            MessageBox.Show("Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void txtDuongDan_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "File txt|*.txt";
            DialogResult result = open.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                txtDuongDan.Text = open.FileName;
            }
        }

        private void txtout_DoubleClick(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "File txt|*.txt";
            DialogResult result = save.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                txtout.Text = save.FileName;
            }
        }

    }
}
